import java
from java.io import IOException
from org.apache.hadoop.io import IntWritable, LongWritable, Text
from org.apache.hadoop.mapreduce import Mapper
from org.apache.hadoop.mapreduce.Mapper import Context
from org.apache.hadoop.mapreduce import Reducer;
from org.apache.hadoop.mapreduce.Reducer import Context;
from org.apache.hadoop.fs import Path;
from org.apache.hadoop.io import IntWritable;
from org.apache.hadoop.mapreduce import Job;
from org.apache.hadoop.mapreduce.lib.input import FileInputFormat;
from org.apache.hadoop.mapreduce.lib.output import FileOutputFormat;
from datetime import datetime
import sys
'''
from wcmapper import WCMapper
from wcreducer import WCReducer
'''

class WCMapper (Mapper):
	def map(self, key, value, context):
		print 'word count mapper'
		context.write(IntWritable(1), IntWritable(1))

class WCReducer (Reducer):
	def reduce(self, key, values, context):
		context.write(key, IntWritable(2))

def main(args):
	input_path = r'/home/ubuntu/wc_test/input.txt'
	output_path = r'/home/ubuntu/wc_test/output' + datetime.now().strftime("%Y%m%d%H%M%S%f")
	job = Job()
	#job.setJarByClass(Main)
	print 'job get jar ', job.getJar()
	print 'mapper ', WCMapper
	job.setMapperClass(WCMapper)
	job.setReducerClass(WCReducer)
	FileInputFormat.addInputPath(job, Path(input_path))
	FileOutputFormat.setOutputPath(job, Path(output_path))
	job.waitForCompletion(True)
	

if __name__ == '__main__':
	'''
	print WCMapper
	print dir(WCMapper)
	print WCMapper.class()
	'''
	main(sys.argv)

